package com.second.statistics.service.impl;

import com.second.common.pojo.R;
import com.second.statistics.dao.SysOperLogDao;

import com.second.statistics.service.SysOperLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.Year;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: clms-second
 * @description:
 * @author: 赵博岩
 * @create: 2021-07-26 15:10
 **/
@Service
public class SysOperLogServiceImpl implements SysOperLogService {
    @Resource
    private SysOperLogDao sysOperLogDao;
    @Override
    public R SysOperLog(String years) {

        //拿到所有已操作的业务类型（0-其他，1-新增，2-修改，3-删除）
        List<Map> list = sysOperLogDao.SysOperLog(years);
//        System.out.println(list);
        List<String> datax=new ArrayList();
        List<Integer> type=new ArrayList();

        //用来存放business_type=1的数据
        List count1=new ArrayList<>();
        List count2=new ArrayList<>();
        List count3=new ArrayList<>();

        //用来存放business_type=1的数据
        List<Map> tt1=new ArrayList<>();
        List<Map> tt2=new ArrayList<>();
        List<Map> tt3=new ArrayList<>();

        //循环遍历分别拿出Key和value
        for (Map map:list){
            datax.add(String.valueOf(map.get("oper_time")));
            type.add(Integer.valueOf(map.get("business_type").toString()));
            if (map.get("business_type").equals(1)){
                tt1.add(map);
                for (Map map1:tt1){
                    count1.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
            if (map.get("business_type").equals(2)){
                tt2.add(map);
                for (Map map1:tt2){
                    count2.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
            if (map.get("business_type").equals(3)){
                tt3.add(map);
                for (Map map1:tt3){
                    count3.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
        }
//        System.out.println(datax);
        //生成一个新的数组xindate用来存储hedate去除重复后的数组
        List newdatax=new ArrayList();
        for (int i=0;i<datax.size();i++){
            if (!newdatax.contains(datax.get(i))){
                newdatax.add(datax.get(i));
            }
        }

        Map logdata=new HashMap();
        logdata.put("newdatax",newdatax);
        logdata.put("type",type);
        logdata.put("count1",count1);
        logdata.put("count2",count2);
        logdata.put("count3",count3);

        return R.success().putObject(logdata);
    }

    @Override
    public R OperaType(String years) {
        //拿到所有已操作的操作类型（0-其他，1-后台，2-手机端）
        List<Map> list=sysOperLogDao.OperaType(years);
//        System.out.println(list);
        List<String> datax=new ArrayList();
        List<Integer> type=new ArrayList();
        //用来存放operator_type=1的数据
        List type1=new ArrayList<>();
        List type2=new ArrayList<>();

        //用来存放operator_type=1的数据
        List<Map> pp1=new ArrayList<>();
        List<Map> pp2=new ArrayList<>();

        for (Map map:list){
//            datax.add(String.valueOf(map.get("oper_time")));
            type.add(Integer.valueOf(map.get("type").toString()));
            if (map.get("operator_type").equals(1)){
                pp1.add(map);
                for (Map map1:pp1){
                    type1.add(Integer.valueOf(map1.get("type").toString()));
                }
            }
            if (map.get("operator_type").equals(2)){
                pp2.add(map);
                for (Map map1:pp2){
                    type2.add(Integer.valueOf(map1.get("type").toString()));
                }
            }
        }
//        //        System.out.println(datax);
//        //生成一个新的数组xindate用来存储hedate去除重复后的数组
//        List newdatax=new ArrayList();
//        for (int i=0;i<datax.size();i++){
//            if (!newdatax.contains(datax.get(i))){
//                newdatax.add(datax.get(i));
//            }
//        }
        Map logdata2=new HashMap();
//        logdata2.put("newdatax",newdatax);
        logdata2.put("type",type);
        logdata2.put("type1",type1);
        logdata2.put("type2",type2);


        return R.success().putObject(logdata2);

    }
}

